package com.zd.controller;
/**
 * @Description: PricelistController
 * @Author:pioneer
 * @Date: 2021-07-14
 * @Version:v1.0
 */

import com.zd.service.lnter.PriceZdServicelnter;
import com.zzg.entity.Price;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;

/**
 * @Description: PricelistController
 * @Author:pioneer
 * @Date: 2021-07-14
 * @Version:v1.0
 */
@Controller
public class PricelistController {
    @Autowired
    private PriceZdServicelnter priceZdServicelnter;

    /**
     * 查询所有信息
     * @param page 页码
     * @param limit 条目数
     * @return 对象集合
     */
    @RequestMapping("queryprice")
    @ResponseBody
    public Map<String,Object> queryprice(int page, int limit){
        System.out.println ("queryprice进：page"+page+"\tlimit"+limit);
        Map<String,Object> map = new HashMap<> ();
        map.put("code","");
        map.put("msg","");
        map.put("count",priceZdServicelnter.selectPricet ().size ());
        map.put("data",priceZdServicelnter.pagingqueryPrice (page,limit));
        System.out.println (map);
        return map;
    }

    /**
     * 根据主键获取Price信息
     * @param priceId
     * @return
     */
    @RequestMapping("getPrice")
    @ResponseBody
    public Price getPrice(String priceId){
        System.out.println ("getPrice进：priceId"+priceId);
        Price price= priceZdServicelnter.getPriceByid (priceId);
        System.out.println (price);
        return price;
    }

    /**
     * 增加信息
     * @param price
     * @param response
     * @throws IOException
     */
    @RequestMapping("addprice")
    public void addprice(Price price, HttpServletResponse response) throws IOException {
        response.setContentType("text/html;charset=utf-8");
        PrintWriter out = response.getWriter();
        int ser=priceZdServicelnter.increasePrice (price);
        if(ser>=0){
            out.write("增加成功");
        }else{
            out.write("增加失败");
        }

    }

    /**
     * 删除信息
     * @param priceId 信息id
     * @param response
     */
    @RequestMapping("delectprice")
    public void delectprice(String priceId, HttpServletResponse response) throws IOException {
        System.out.println ("delectprice ：进"+priceId);
        response.setContentType("text/html;charset=utf-8");
        PrintWriter out = response.getWriter();
        if(priceId!=null){
            int ser=priceZdServicelnter.delectPrice (priceId);
            if(ser>=0){
                out.write("删除成功");
            }else{
                out.write("删除失败");
            }
        }
    }
}
